/* 克隆出行人员 */
function clone_tripcrew(a) {
	var file_show = $(a).prev(".sgdp_public_moreinput_div").children(".sgdp_file_button").children("#sgdp_file_NO").is(
		":hidden"); //判断文件上传是否是隐藏的
	var pd_show = $(a).prev(".sgdp_public_moreinput_div").children(".a_img_Esc").is(":hidden");
	var s = '';
	if (pd_show) { //判断A标签是隐藏还是显示 如果是隐藏
		//判断file 上传文件是否隐藏 隐藏也就是选择了文件
		if (file_show == true) { //如果隐藏 就设置它显示，上传成功隐藏
			//首先让他显示
			$(a).prev(".sgdp_public_moreinput_div").children(".a_img_Esc").show();
			$(a).prev(".sgdp_public_moreinput_div").children(".sgdp_file_button").children("#sgdp_file_NO").show();
			$(a).prev(".sgdp_public_moreinput_div").children(".sgdp_file_button").children("#sgdp_file_YES").hide();
			//再克隆，
			var s = $(a).prev(".sgdp_public_moreinput_div").clone();
			$(a).prev(".sgdp_public_moreinput_div").children(".sgdp_file_button").children("#sgdp_file_NO").hide();
			$(a).prev(".sgdp_public_moreinput_div").children(".sgdp_file_button").children("#sgdp_file_YES").show();
			//再隐藏
			$(a).prev(".sgdp_public_moreinput_div").children(".a_img_Esc").hide();
		} else {
			//首先让他显示
			$(a).prev(".sgdp_public_moreinput_div").children(".a_img_Esc").show();
			//再克隆，
			s = $(a).prev(".sgdp_public_moreinput_div").clone();
			//再隐藏
			$(a).prev(".sgdp_public_moreinput_div").children(".a_img_Esc").hide();
		}
	} else { //如果是显示
		//判断file 上传文件是否隐藏 隐藏也就是选择了文件
		if (file_show == true) { //如果隐藏 就设置它显示，上传成功隐藏
			//首先让他显示
			$(a).prev(".sgdp_public_moreinput_div").children(".sgdp_file_button").children("#sgdp_file_NO").show();
			$(a).prev(".sgdp_public_moreinput_div").children(".sgdp_file_button").children("#sgdp_file_YES").hide();
			//再克隆，
			s = $(a).prev(".sgdp_public_moreinput_div").clone();
			$(a).prev(".sgdp_public_moreinput_div").children(".sgdp_file_button").children("#sgdp_file_NO").hide();
			$(a).prev(".sgdp_public_moreinput_div").children(".sgdp_file_button").children("#sgdp_file_YES").show();
		} else {
			//直接克隆
			s = $(a).prev(".sgdp_public_moreinput_div").clone();
		}
	}
	var str = '';
	for (var i = 0; i < s.length; i++) {
		str += s.html();
	}
	var text = '<div class="sgdp_public_moreinput_div">' + str + "</div>";
	$(a).prev(".sgdp_public_moreinput_div").after(text)
}
/* 克隆出行目的地 */
function clone_content(a) {
	var pd_show = $(a).prev(".sgdp_public_includespan_div").children("div").children(".a_img_Esc").is(":hidden");
	var span_number = $(a).prev(".sgdp_public_includespan_div").children("div").children(".span_title").children(".span_number").html();
	var number=parseInt(span_number)+1;
	if (pd_show) { //判断A标签是隐藏还是显示 如果是隐藏
		//首先让他显示
		$(a).prev(".sgdp_public_includespan_div").children("div").children(".a_img_Esc").show();
		$(a).prev(".sgdp_public_includespan_div").children("div").children(".span_title").children(".span_number").html(number);
		//再克隆，
		var s = $(a).prev(".sgdp_public_includespan_div").clone();
		//再隐藏
		$(a).prev(".sgdp_public_includespan_div").children("div").children(".a_img_Esc").hide();
		$(a).prev(".sgdp_public_includespan_div").children("div").children(".span_title").children(".span_number").html(span_number);
		var str = '';
		for (var i = 0; i < s.length; i++) {
			str += s.html();
		}
		var text = '<div class="sgdp_public_includespan_div">' + str + "</div>";
		$(a).prev(".sgdp_public_includespan_div").after(text)
	} else { //如果是显示
		//直接克隆
		$(a).prev(".sgdp_public_includespan_div").children("div").children(".span_title").children(".span_number").html(number);
		var s = $(a).prev(".sgdp_public_includespan_div").clone();
		$(a).prev(".sgdp_public_includespan_div").children("div").children(".span_title").children(".span_number").html(span_number);
		
		var str = '';
		for (var i = 0; i < s.length; i++) {
			str += s.html();
		}
		var text = '<div class="sgdp_public_includespan_div">' + str + "</div>";
		$(a).prev(".sgdp_public_includespan_div").after(text)
	}
}
/* 克隆车辆安排 */
function clone_cararrange(a) {
	var pd_show = $(a).prev(".sgdp_public_includespan_div").children(".spid_div").children(".a_img_Esc").is(":hidden");
	var span_number = $(a).prev(".sgdp_public_includespan_div").children(".spid_div").children(".span_title").children(".span_number").html();
	var number=parseInt(span_number)+1;
	var s = "";
	if (pd_show) { //判断A标签是隐藏还是显示 如果是隐藏
		//首先让他显示
		$(a).prev(".sgdp_public_includespan_div").children("div").children(".span_title").children(".span_number").html(number);
		$(a).prev(".sgdp_public_includespan_div").children(".spid_div").children(".a_img_Esc").show();
		//再克隆，
		 s = $(a).prev(".sgdp_public_includespan_div").clone();
		//再隐藏
		$(a).prev(".sgdp_public_includespan_div").children(".spid_div").children(".a_img_Esc").hide();
		$(a).prev(".sgdp_public_includespan_div").children("div").children(".span_title").children(".span_number").html(span_number);
		
	} else { //如果是显示
		//直接克隆
		$(a).prev(".sgdp_public_includespan_div").children("div").children(".span_title").children(".span_number").html(number);
		s = $(a).prev(".sgdp_public_includespan_div").clone();
		$(a).prev(".sgdp_public_includespan_div").children("div").children(".span_title").children(".span_number").html(span_number);
	}
	var str = '';
	for (var i = 0; i < s.length; i++) {
		str += s.html();
	}
	var text = '<div class="sgdp_public_includespan_div">' + str + "</div>";
	$(a).prev(".sgdp_public_includespan_div").after(text)
}


/* 出行人员删除 */
function sgdp_moreinput_clear(a){
	$(a).parent().remove();
}
/* 出行目的地删除 */
function sgdp_crewdestination_clear(a){
	$(a).parent().parent().remove();
	var count =$(".sgdp_crewdestination_div .sgdp_public_includespan_div div .span_title .span_number").size();
	for(var i =0;i<count;i++){
		$(".sgdp_crewdestination_div .sgdp_public_includespan_div div .span_title .span_number:eq("+i+")").html(i+1)
	}
}
/* 车辆安排 */
function sgdp_cararrange_clear(a){
	$(a).parent().parent().remove();
	var count =$(".sgdp_cararrange_div .sgdp_public_includespan_div .spid_div .span_title .span_number").size();
	for(var i =0;i<count;i++){
		$(".sgdp_cararrange_div .sgdp_public_includespan_div .spid_div .span_title .span_number:eq("+i+")").html(i+1)
	}
}

var this_a;
/* 点击选择文件 */
function file_button(a) {
	$(a).next().click();
	this_a = $(a);
	$($(a).next()).change(function() {
		var imgfFile = $(a).next().prop("files")[0];
		if (null != imgfFile) {
			$(a).children("#sgdp_file_NO").hide(600);
			$(a).children("#sgdp_file_YES").show(600);

		} else {
			$(a).children("#sgdp_file_NO").show(600);
			$(a).children("#sgdp_file_YES").hide(600);
		}
	});

}
/* -----------提交----------- */
function sgdp_form_submit() {
	if (pd()) {
		$(".sgdp_form").submit();
	}
}

/* -----------验证----------- */
function pd() {
	var number_pd = /^\d+$/; //验证输入的是否是数字
	var mobileReg_phone = /^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\d{8}$|^0\d{2,3}-?\d{7,8}$/; //既验证手机号也验证固定电话 
	/* 验证所有INPUT */
	$("form input").each(function() {
		/* -----------判断表单是input-----------t */
		if ($(this).is("input[type='text']")) {
			if ($(this).val() == "") {
				$(this).css("border", "0.5px solid red");
				var placeholder = $(this).attr("placeholder");
				layer.msg('请输入' + placeholder, {
					icon: 2
				});
				return false;
			} else {
				$(this).css("border", "0.5px solid #CCCCCC");
				/* -----------验证所有手机号----------- */
				if ($(this).attr("placeholder") == "联系方式") {
					if (mobileReg_phone.test($(this).val()) == false) {
						$(this).css("border", "0.5px solid red");
						var placeholder = $(this).attr("placeholder");
						layer.msg('请输入正确的' + placeholder, {
							icon: 2
						});
						return false;
					} else {
						$(this).css("border", "0.5px solid #CCCCCC");
					}
				}
				/* 验证所有输入数字 */
				if ($(this).attr("placeholder") == "人数") {
					if (number_pd.test($(this).val()) == false) {
						$(this).css("border", "0.5px solid red");
						var placeholder = $(this).attr("placeholder");
						layer.msg('请输入正确的' + placeholder, {
							icon: 2
						});
						return false;
					} else {
						$(this).css("border", "0.5px solid #CCCCCC");
					}
				}
			}
		}
		/* -----------判断表单是date---- */
		if ($(this).is("input[type='date']")) {

			var go_date = $(".go_date").val();
			if (go_date.length <= 0 || null == go_date) {
				layer.msg('请输入出发时间', {
					icon: 2
				});
				$(".go_date").css("border", "0.5px solid red");
				return false;
			} else {
				$(".go_date").css("border", "0.5px solid #CCCCCC");
			}
			var go_time = $(".go_time").val();
			if (go_time.length <= 0 || null == go_time) {
				layer.msg('请输入出发时间', {
					icon: 2
				});
				$(".go_time").css("border", "0.5px solid red");
				return false;
			} else {
				$(".go_time").css("border", "0.5px solid #CCCCCC");
			}

			var end_date = $(".end_date").val();
			if (end_date.length <= 0 || null == end_date) {
				layer.msg('请输入反置时间', {
					icon: 2
				});
				$(".end_date").css("border", "0.5px solid red");
				return false;
			} else {
				$(".end_date").css("border", "0.5px solid #CCCCCC");
			}
			var end_time = $(".end_time").val();
			if (end_time.length <= 0 || null == end_time) {
				layer.msg('请输入反置时间', {
					icon: 2
				});
				$(".end_time").css("border", "0.5px solid red");
				return false;
			} else {
				$(".end_time").css("border", "0.5px solid #CCCCCC");
			}

			if (go_date > end_date) {
				layer.msg('反置时间不能低于出发时间', {
					icon: 2
				});
				$(".end_date").css("border", "0.5px solid red");
				return false;
			} else {
				$(".end_date").css("border", "0.5px solid #CCCCCC");
			}
		}
	})
}
